<template>
<section class="header-wrapper">
  <router-link tag="div" to="/" class="arrow-abs" v-if="showFixed">
    <span class="iconfont icon-back">&#xe624;</span>
  </router-link>
  <div class="fixed-title" v-else :style="opacityStyle">
    <span class="iconfont icon-fixed-back">&#xe624;</span>
    海洋世界
  </div>
</section>

</template>
<script>
export default {
  name: 'detailHeader',
  data () {
    return {
      showFixed: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      let top = document.documentElement.scrollTop
      if (top > 40) {
        let opacity = top / 120
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
        this.showFixed = false
      } else {
        this.showFixed = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>
<style lang="stylus" scoped>
@import '~styles/variable.styl'
.header-wrapper
  .arrow-abs
    position absolute
    top .2rem
    left .2rem
    padding .2rem
    background-color rgba(0, 0, 0, .8)
    border-radius .6rem
    .icon-back
      color #fff
  .fixed-title
    position fixed
    top 0
    right 0
    left 0
    line-height .8rem
    text-align center
    background-color $bgColor
    color #fff
    .icon-fixed-back
      position absolute
      left .2rem
</style>
